package com.applet.applet_shangcheng.dao;

import com.applet.applet_shangcheng.entity.Images;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ImagesMapper {
    /*  @Insert({
              "insert into tb_images (file_name,image_url,status) values (#{fileName},#{imageUrl},#{status})"
      })
      @Options(useGeneratedKeys = true, keyProperty = "id")
      int insertImage(@Param("fileName")String fileName,@Param("imageUrl")String imageUrl,@Param("status") String status);*/
    @Insert({
            "insert into tb_images (file_name,image_url,status) values (#{fileName},#{imageUrl},#{status})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertImage(Images images);

    @Select({
            "select id,file_name,image_url,status from tb_images"
    })
    List<Images> selectImage();

    @Select({
            "select file_name from tb_images where status = 0"
    })
    List<String> findByStatus();


    @Select({
            "select id,file_name,image_url,,status from tb_images where image_url=#{imageUrl}"
    })
    List<Images> findByUrl(@Param("imageUrl") String imageUrl);

    @Delete({
            "delete from tb_images where file_name=#{fileName}"
    })
    int deleteImage(@Param("fileName") String fileName);

    @Update({
            "update tb_images set status = 0 where image_url =#{imageUrl}"
    })
    int updateImageStatus(@Param("imageUrl") String imageUrl);

    @Update({
            "update tb_images set status = #{status} where image_url =#{image}"
    })
    void InsertImageStatus(@Param("image")String image,@Param("status")String status);
}
